<template>
	<view class="wrap">
		<view class="header">
			<view class="userinfo">
				<view class="image" @click="navTo('info')">
					<u-avatar size="100" :src="avatarUrl"></u-avatar>
				</view>
				<view class="info" style="display: flex;justify-content: space-between;">
					<view @click="navTo('info')">
						<view class="username">{{ state.name }}</view>
            <view class="list-tags">
              <view v-if="state.roleName" class="item-tag">{{ state.roleName }}</view>
              <view v-if="state.deptName" class="item-tag">{{ state.deptName }}</view>
            </view>
					</view>
					<view class="sign-in-images">
            <image src="/static/assets/images/sign-in.png"></image>
          </view>
				</view>
			</view>
		</view>
		<u-gap height="20" bg-color="#f5f5f5"></u-gap>
		<u-cell-group :border="false">
			<u-cell-item v-if="false" icon="setting" :iconStyle="{ color: '#2767dc' }" title="服务器地址设置" @click="navTo('server')" :arrow="true"></u-cell-item>
			<u-cell-item icon="download" :iconStyle="{ color: '#ff8a00' }" title="检查更新"  @click="navTo('version')" :arrow="true"></u-cell-item>
			<u-cell-item icon="grid" :iconStyle="{ color: '#59bdf9' }" title="配置数据更新" @click="handleUpdateConfig" :arrow="true"></u-cell-item>
		</u-cell-group>
		<u-gap height="20" bg-color="#f5f5f5"></u-gap>
		<view>
			<u-button class="sign-out" @click="logout" :hair-line="false">退出登录</u-button>
		</view>
	</view>
</template>

<script>
import { logout } from '@/api/system/user.js'
import userSer from '@/pages/common/service/user.js'
import { getUserState, avatarUrl, storeAvatar } from './info.vue'

export default {
	data() {
		return {
			iconSize: 38,
			state: {
				id: '',
				name: '',
        roleName: '',
        deptName: '',
				sex: '',
				email: '',
				phonenumber: ''
			},
			avatarUrl: '',
			signatureUrl: ''
		}
	},
	onLoad() {
		// 获取用户信息
    this.getUserState(this)
  },
	methods: {
    getUserState,
		storeAvatar,
    initView () {},
		navTo(url) {
			uni.navigateTo({
				url: url
			})
		},
		logout() {
      userSer.logout({ vm: this })
		},
		// 更新配置数据
		handleUpdateConfig () {
			uni.reLaunch({
				url: '/pages/sys/user/update?type=2'
			})
		}
	}
};
</script>
<style lang="scss">
@import 'index.scss';
page {
	background-color: #f5f5f5;
}
.wrap .u-cell-box .u-cell_title{
	color:#202328;
}
.sign-in-images{
	width: 125rpx;
	height:50rpx;
	position: absolute;
	right: 0;
	top:5px;
	uni-image{
		width: 125rpx;
		height:50rpx;
	}
}
</style>
